home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / gnu / groff108.lha / groff-1.08 / libgroff / cset.cc < prev    next >
C/C++ Source or Header  |  1992-08-03  |  2KB  |  102 lines

  1. // -*- C++ -*-
  2. /* Copyright (C) 1989, 1990, 1991, 1992 Free Software Foundation, Inc.
  3.      Written by James Clark (jjc@jclark.com)
  4.  
  5. This file is part of groff.
  6.  
  7. groff is free software; you can redistribute it and/or modify it under
  8. the terms of the GNU General Public License as published by the Free
  9. Software Foundation; either version 2, or (at your option) any later
  10. version.
  11.  
  12. groff is distributed in the hope that it will be useful, but WITHOUT ANY
  13. WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  15. for more details.
  16.  
  17. You should have received a copy of the GNU General Public License along
  18. with groff; see the file COPYING.  If not, write to the Free Software
  19. Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
  20.  
  21. #include <ctype.h>
  22. #include "cset.h"
  23.  
  24. cset csalpha(CSET_BUILTIN);
  25. cset csupper(CSET_BUILTIN);
  26. cset cslower(CSET_BUILTIN);
  27. cset csdigit(CSET_BUILTIN);
  28. cset csxdigit(CSET_BUILTIN);
  29. cset csspace(CSET_BUILTIN);
  30. cset cspunct(CSET_BUILTIN);
  31. cset csalnum(CSET_BUILTIN);
  32. cset csprint(CSET_BUILTIN);
  33. cset csgraph(CSET_BUILTIN);
  34. cset cscntrl(CSET_BUILTIN);
  35.  
  36. #define ISASCII(c) isascii(c)
  37. #if 0
  38. #define ISASCII(c) 1 /* use this is you have an ANSI ctype.h */
  39. #endif
  40.  
  41. void cset::clear()
  42. {
  43.   char *p = v;
  44.   for (int i = 0; i <= UCHAR_MAX; i++)
  45.     p[i] = 0;
  46. }
  47.  
  48. cset::cset()
  49. {
  50.   clear();
  51. }
  52.  
  53. cset::cset(const char *s)
  54. {
  55.   clear();
  56.   while (*s)
  57.     v[(unsigned char)*s++] = 1;
  58. }
  59.  
  60. cset::cset(const unsigned char *s)
  61. {
  62.   clear();
  63.   while (*s)
  64.     v[*s++] = 1;
  65. }
  66.  
  67. cset::cset(cset_builtin)
  68. {
  69.   // these are initialised by cset_init::cset_init()
  70. }
  71.  
  72. cset &cset::operator|=(const cset &cs)
  73. {
  74.   for (int i = 0; i <= UCHAR_MAX; i++)
  75.     if (cs.v[i])
  76.       v[i] = 1;
  77.   return *this;
  78. }
  79.  
  80.  
  81. int cset_init::initialised = 0;
  82.  
  83. cset_init::cset_init()
  84. {
  85.   if (initialised)
  86.     return;
  87.   initialised = 1;
  88.   for (int i = 0; i <= UCHAR_MAX; i++) {
  89.     csalpha.v[i] = ISASCII(i) && isalpha(i);
  90.     csupper.v[i] = ISASCII(i) && isupper(i);
  91.     cslower.v[i] = ISASCII(i) && islower(i);
  92.     csdigit.v[i] = ISASCII(i) && isdigit(i);
  93.     csxdigit.v[i] = ISASCII(i) && isxdigit(i);
  94.     csspace.v[i] = ISASCII(i) && isspace(i);
  95.     cspunct.v[i] = ISASCII(i) && ispunct(i);
  96.     csalnum.v[i] = ISASCII(i) && isalnum(i);
  97.     csprint.v[i] = ISASCII(i) && isprint(i);
  98.     csgraph.v[i] = ISASCII(i) && isgraph(i);
  99.     cscntrl.v[i] = ISASCII(i) && iscntrl(i);
  100.   }
  101. }
  102.